#ifndef SERIAL_H
#define SERIAL_H

#include <QObject>
#include <QtCore>
#include <QtSerialPort/QSerialPort>
#include <QDebug>
#include <QTimer>

class Serial : public QObject
{
    Q_OBJECT
public:
    explicit Serial( QObject *parent = Q_NULLPTR);
    ~Serial();

    bool open(const QString &dev, QSerialPort::BaudRate baud);
    bool send(const QByteArray &data);
    void setFrameGap(int msec);

private:
    QSerialPort *port;
    bool isConnected;
    QTimer *frameTimer;
    QByteArray rxData;

signals:
    void frameIn(const QByteArray &data);

public slots:

private slots:
    void onFrameTimeout();
    void onRX();
};

#endif // SERIAL_H
